home *** CD-ROM | disk | FTP | other *** search
/ DOpus Plus / DOpus Plus.iso / Tutorial / C Guide / Code_Fragments / ScanTree.c < prev    next >
C/C++ Source or Header  |  1998-09-18  |  4KB  |  99 lines

  1.  
  2. #include <dos/exall.h>
  3.  
  4. typedef struct
  5. {    char mem[4096];
  6.      BPTR lock;
  7.      struct FileInfoBlock *fib;
  8.      struct ExAllData *ead;
  9.      struct ExAllControl *eac;
  10.      Att_Node *dirnode;
  11.      Att_Node *remnode;
  12.      Att_List *dirlist;
  13.      char string[256];
  14. } Combi;
  15.  
  16.  
  17. // the argument "entrylist" must be already intialized.
  18. // you will get the results in this list... 
  19.  
  20. BOOL Recurse( Att_List *entrylist ) // needs for me for 40MB 2 mins...
  21. {     
  22.      Combi *combi;
  23.      
  24.      BOOL ret = TRUE; 
  25.      
  26.      if( (combi = AllocMemH(mempool, sizeof(Combi))) )
  27.        {
  28.           if( (combi->fib = AllocDosObject(DOS_FIB, NULL)) )
  29.             {
  30.                if( (combi->eac = AllocDosObject(DOS_EXALLCONTROL, NULL)) )
  31.                  {
  32.                     combi->dirlist = Att_NewList( LISTF_POOL );
  33.                     combi->dirnode = (Att_Node *) entrylist->list.lh_Head;
  34.                     
  35.                     while( combi->dirnode->node.ln_Succ )
  36.                       {
  37.                          combi->lock = Lock( combi->dirnode->node.ln_Name, SHARED_LOCK );
  38.           
  39.                          Examine( combi->lock, combi->fib );
  40.                          
  41.                          UnLock( combi->lock );
  42.            
  43.                          if( combi->fib->fib_DirEntryType > 0 )
  44.                            {
  45.                               Att_NewNode( combi->dirlist, combi->dirnode->node.ln_Name, NULL, NULL );
  46.                               
  47.                               if( combi->dirnode->data )
  48.                                    FreeMemH( (APTR) combi->dirnode->data );
  49.                                    
  50.                               combi->dirnode = (Att_Node *) (combi->remnode = combi->dirnode)->node.ln_Succ;
  51.                
  52.                               Att_RemNode( combi->remnode );
  53.                                
  54.                            }
  55.                          else 
  56.                               combi->dirnode = (Att_Node *) combi->dirnode->node.ln_Succ;
  57.                       }
  58.              
  59.                     while( (combi->dirnode = (APTR) combi->dirlist->list.lh_Head)->node.ln_Succ )
  60.                       {
  61.                          combi->lock = Lock( combi->dirnode->node.ln_Name, SHARED_LOCK );
  62.                          combi->eac->eac_LastKey = 0;
  63.                           
  64.                          do
  65.                            {
  66.                               combi->ead = (APTR) combi->mem;
  67.                                                                                 
  68.                               if( (!(ret = ExAll(combi->lock, combi->ead, 4096, ED_TYPE, combi->eac)) &&
  69.                                    IoErr() != ERROR_NO_MORE_ENTRIES) )
  70.                                    break;
  71.                                                                                           
  72.                               if( !combi->eac->eac_Entries )
  73.                                    continue;
  74.                                
  75.                               do
  76.                                 {
  77.                                    strcpy( combi->string, combi->dirnode->node.ln_Name );
  78.                                    AddPart( combi->string, combi->ead->ed_Name, 256 );
  79.                                    Att_NewNode( combi->ead->ed_Type < 0 ? entrylist : combi->dirlist, combi->string, NULL, ADDNODEF_EXCLUSIVE );
  80.                                 }
  81.                               while( (combi->ead = combi->ead->ed_Next) );
  82.                            }
  83.                          while( ret );
  84.           
  85.                          UnLock( combi->lock );
  86.                          Att_RemNode( combi->dirnode ); 
  87.                       }
  88.                       
  89.                     Att_RemList( combi->dirlist, NULL );
  90.                                         
  91.                     FreeDosObject( DOS_EXALLCONTROL, combi->eac );
  92.                  }
  93.                FreeDosObject( DOS_FIB, combi->fib );
  94.             }
  95.           FreeMemH( combi );
  96.        }
  97.      return ret;
  98. }   
  99.